package com.graduate.daydayup.adpter

import android.graphics.drawable.GradientDrawable
import android.util.Log
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SPUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.graduate.daydayup.R
import com.graduate.daydayup.room.Schedule
import com.zhuangfei.timetable.model.ScheduleColorPool
import java.util.*

class LessonAdapter(layoutResId: Int, list: MutableList<Schedule>) : BaseQuickAdapter<Schedule, BaseViewHolder>(layoutResId, list) {
    lateinit var mListen: OnItemClickListener //接口可以延时加载
    override fun convert(holder: BaseViewHolder, item: Schedule) {
        val default="8:20,\n9:15,\n10:15,\n11:10,\n13:00,\n13:55,\n14:50,\n16:45,\n18:30,\n19:25,\n20:20"
        var time=""
        holder.setText(R.id.tv_name, item.name + "课")
        var   start = item.start-1
        if (SPUtils.getInstance().getString("lessontime")!=null&&!SPUtils.getInstance().getString("lessontime").isEmpty()){
            val replace = SPUtils.getInstance().getString("lessontime").replace("\n", "")
            val split = replace.split(",")
            val split1 = split[start].split(":")
            time=split[start]

        }else{
            val replace = default.replace("\n", "")
            val split = replace.split(",")
            val split1 = split[start].split(":")
            Log.d("设置闹钟", split1[0] + split1[1])
            time=split[start]
      }
        holder.setText(R.id.tv_time, time)
        holder.setText(R.id.tv_room, item.room)
        holder.setText(R.id.tv_teacher, "|" + item.teacher + "老师")
        GradientDrawable()
        holder.itemView.setOnClickListener {
            mListen.onItemClick(holder.layoutPosition)
        }

        val scheduleColorPool = ScheduleColorPool(context)
        holder.setBackgroundColor(R.id.cv_today, context.resources.getColor(R.color.blue_skr))

        LogUtils.e("颜色${item.colorRandom}")
    }

    interface OnItemClickListener{
        fun onItemClick(pos: Int)
    }

    fun setOnItemClickListener(clickListener: OnItemClickListener){
        this.mListen=clickListener;
    }
}